package com.reeves.service.impl;

import com.reeves.service.TestStartWithUrlService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Reeves on 2017/7/8.
 */

@Service
public class TestStartWithUrlServiceImpl implements TestStartWithUrlService {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public String testStartWithUrl(String processId) {
        Deployment deployment = repositoryService.createDeployment().name("测试Activiti").addClasspathResource("diagrams/helloworld.png").addClasspathResource("diagrams/helloworld.bpmn").deploy();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processId);

        String returnStr = "{\"部署ID\":"+deployment.getId()+"\"部署名称\":"+deployment.getName()+"\"流程实例ID\":"+processInstance.getId()+"\"流程定义ID\":"+processInstance.getProcessDefinitionId()+"}";
        return returnStr;
    }
}
